window.onload=function(){

    var app=new Vue({
        el:"#app",
        data:{
            sysuser:[],
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            dialogVisible:false,
            beisysuser:{
                uaid:"",
                username:"",
                phone:"",
                email:"",
                password:"",
                checkList:[],
                passwordtwo:""
            },
            rolearray:[],
            arrayindex:[],
            deleteSysUser:false
        },
        methods:{
           iniststudent(){
                //初始化数据
                methodaxios.get(null,"/sys/query?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize,rep=>{
                    window.console.log("我进来了")
                    window.console.log(rep)
                    window.console.log("=======================")
                    window.console.log(rep.data.data.data);
                    this.sysuser=rep.data.data.data;
                    for (var i=0;i<this.sysuser.length;i++)
                    {
                        var names="";
                        for (var j=0;j<this.sysuser[i].beiSysRole.length;j++)
                        {
                            names+=this.sysuser[i].beiSysRole[j].rname+",";
                        }
                        this.sysuser[i].rname=names;
                        var dateee = new Date( this.sysuser[i].lastLoginTime).toJSON();
                        this.sysuser[i].lastLoginTime=new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
                    }
                    this.pagination.total=rep.data.data.total;
                })

               //初始化数据
               methodaxios.get(null,"/role/querys",rep=>{
                   this.rolearray=rep.data
               })
            },
            //当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.iniststudent();
            },
            //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.iniststudent();
            },
            inisrole(){

            },
            updateuser(auid){//修改按钮
            window.console.log(auid)
                this.beisysuser.uaid=this.sysuser[auid].uaid;
                this.beisysuser.username=this.sysuser[auid].username;
                this.beisysuser.phone=this.sysuser[auid].phone;
                this.beisysuser.email=this.sysuser[auid].email;
                this.beisysuser.checkList=[]
                for (var j=0;j<this.sysuser[auid].beiSysRole.length;j++)
                {
                    this.beisysuser.checkList.push(this.sysuser[auid].beiSysRole[j].rid)
                }
               // this.beisysuser.checkList=this.sysuser[auid].checkList;
               this.dialogVisible=true
            },
            sysupdate(){//确定修改
                if(isBlank(this.beisysuser.username)){
                    layer.msg("请输入用户名");
                    return false;
                }
                //如果密码不为空
                if(isBlank(this.beisysuser.password)){
                    layer.msg("请输入密码");
                    return false;
                }
                if(this.beisysuser.password.length<6){
                    layer.msg("请正确输入密码");
                    return ;
                }
                if(isNotPhone(this.beisysuser.phone)){
                    layer.msg("请正确输入电话号码");
                    return ;
                }
                if(isNotEmail(this.beisysuser.email)){
                    layer.msg("请正确输入邮箱");
                    return ;
                }
                if(this.beisysuser.password!=this.beisysuser.passwordtwo){
                    layer.msg("两次密码不一致");
                    return ;
                }
                this.beisysuser.password=MD5(this.beisysuser.password);
                window.console.log("我进来了=====================")
                window.console.log(this.beisysuser)
               methodaxios.post("/sys/update",this.beisysuser,(rep)=>{
                    if(rep.data.code==="1000"){
                        layer.msg(rep.data.msg);
                    }
                    if(rep.data.code==="200"){
                        this.dialogVisible=false
                        layer.msg("修改成功");
                        this.beisysuser.password=""
                        this.beisysuser.passwordtwo=""
                        this.iniststudent();
                    }
                })
            },
            deleteuser(uaid,username){
               this.beisysuser.username=username;
                this.beisysuser.uaid=uaid;
               this.deleteSysUser=true;
            },
            sysdelete(){
                //初始化数据
                methodaxios.get({uaid:this.beisysuser.uaid},"/sys/delete",rep=>{
                    if(rep.data.code==="200"){
                        this.deleteSysUser=false
                        layer.msg("删除成功");
                        this.iniststudent();
                    }
                })
            }

        },
        mounted() {
            this.iniststudent();
            this.inisrole();
        }

    })


}